/**************************************************************
 *
 * userprog/ksyscall.h
 *
 * Kernel interface for systemcalls 
 *
 * by Marcus Voelp  (c) Universitaet Karlsruhe
 *
 **************************************************************/

#ifndef __USERPROG_KSYSCALL_H__ 
#define __USERPROG_KSYSCALL_H__ 

#include "kernel.h"
#include "openfile.h"
#include "addrspace.h"




void SysHalt()
{
  kernel->interrupt->Halt();
}


int SysAdd(int op1, int op2)
{
  return op1 + op2;
}

void StartProcess(char *filename)
{
	kernel->lstaddrspace->Front()->SaveReg();
	DEBUG(dbgGxc,"step7---in StartProcess\n");
    OpenFile *executable = kernel->fileSystem->Open(filename);
    cout << "executable file is "<< executable<<endl;
    AddrSpace *space;
    if (executable == NULL)
    {
		printf("Unable to open file %s\n", filename);
		return;
    }
    space = new AddrSpace(executable);
    DEBUG(dbgGxc,"step8---second back from AddrSpace\n");
    delete executable;			// close file


    kernel->currentThread->space = space;

//    space->InitRegisters();		// set the initial register values
//    space->RestoreState();		// load page table register
//    kernel->machine->Run();			// jump to the user progam
//    ASSERT(FALSE);			// machine->Run never returns;

    space->Execute();
					// the address space exits
				// by doing the syscall "exit"
}





#endif /* ! __USERPROG_KSYSCALL_H__ */
